/**
 * Copyright (c) 2018-present, Chen Guodong
 * All rights reserved.
 *
 * @flow
 */


<template>
  <section class="content">
    <Header title="已购班课">
      <div slot="left" @click="goBack" style="width: 100%;height: 100%;text-align: center;">
        <i class="iconfont icon-arrow-left" style="font-size: 22px"></i>
      </div>
    </Header>
    <div class="main">
      <Divider v-if="list && list.length === 0">您暂时没有购买记录</Divider>
      <div ref="mescroll" class="mescroll">
        <ul id="dataList">
          <li v-for="(item,index) in list" :key="index" @click="goDetail(item.id)">
            <div class="top">
              <div class="left">
                <img :src="item.litpic" alt>
              </div>
              <div class="right">
                <p class="title">{{item.sname}}-{{item.name}}</p>
                <!-- <div class="info_box">
                  <b class="type">{{item.price === 1 ? `${item.price}卷` : `免费`}}</b>
                  <b class="status" v-if="item.type===1">购买</b>
                </div>-->
              </div>
            </div>
            <!-- <p class="bottom">创建时间:&nbsp;{{item.create_time}}</p> -->
          </li>
        </ul>
      </div>
      <!-- </mescroll-vue> -->
    </div>
  </section>
</template>

<script>
import Header from "../../components/Header/Header";
import MeScroll from "mescroll.js";
import moment from "moment";
import { Divider } from 'vux'
import { reqBuyed } from "../../api/index.js";

export default {
  data() {
    return {
      list: [],
      mescroll: {}
    };
  },
  mounted() {
    self = this;
    self.mescroll = new MeScroll(self.$refs.mescroll, {
      down: {
        auto: true,
        callback: self.downCallback,
        textInOffset: "下拉刷新",
        textOutOffset: "松开立即刷新",
        textLoading: `<p>正在加载数据中...</p><p>最后更新: 今天${moment().format(
          "HH:mm"
        )}</p>`,
        empty: {
          // 列表第一页无任何数据时,显示的空提示布局; 需配置warpId才生效;
          warpId: "content", // 父布局的id;
          tip: "暂无相关数据~", // 提示
          lazyLoad: {
            use: false // 是否开启懒加载,默认false
          }
        }
      }
    });
  },
  methods: {
    goDetail(data) {
      this.$router.push({ path: "/kechengDetail", query: { id: data } });
    },
    goBack() {
      if (window.history.length <= 1) {
        this.$router.push({ path: "/" });
        return false;
      } else {
        this.$router.go(-1);
      }
    },
    // 下拉刷新
    async downCallback(mescroll) {
      const result = await reqBuyed({});
      if (result.code === 1) {
        this.list = result.data.items;
        this.$nextTick(() => {
          mescroll.endSuccess(result.data.length);
        });
      } else {
        this.$vux.toast.show(`获取看课记录失败:${result.msg}`);
        this.$nextTick(() => {
          mescroll.endErr();
        });
      }
    }
  },
  components: { Header, Divider }
};
</script>

<style lang='less' scoped>
@import "../../util/theme.less";

.content {
  .be-full();
  .main {
    width: 100%;
    height: calc(~"100% - 46px");
    ul {
      box-sizing: border-box;
      width: 100%;
      li {
        padding: 0 10px;
        box-sizing: border-box;
        background: @white;
        margin-bottom: 15px;
        .top {
          border-bottom: 1px solid @border-base;
          .mix-flex-center();
          height: 90px;
          position: relative;
          box-sizing: border-box;
          padding: 10px 0;
          .left {
            height: 100%;
            flex: 3;

            img {
              width: 100%;
              height: 100%;
              border-radius: 5px;
              overflow: hidden;
            }
          }
          .right {
            width: 100%;
            height: 100%;
            flex: 7;
            padding-left: 10px;
            position: relative;
            .title {
            }
            .info_box {
              position: absolute;
              bottom: 0;
              width: 100%;
              .type {
                color: red;
              }
              .status {
                position: absolute;
                right: 10px;
                top: 0;
                font-size: 10px;
                border: 1px solid @red;
                color: @white;
                background: @red;
                padding: 0 3px;
                border-radius: 3px;
              }
            }
          }
        }
        .bottom {
          line-height: 30px;
          font-size: 12px;
          text-align: left;
          color: @font-secondary;
        }
      }
    }
  }
}
</style>
